﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceBus.Contract;

namespace ServiceBus.EndPoint
{
    public class SAOServiceStructre<T> where T:IStandardService 
    {
        public SAOServiceStructre(string servicename, string address)
        {
            this.ServiceName = servicename;
            this.Address = address;
            MessageDistributor.CreateMessageService(servicename, address);
            FunctionServiceConnector.CreateFunctionService<T>(servicename, address);
        }
        public string ServiceName { get; private set; }
        public string Address { get; private set; }
        public ServiceBus.EndPoint.MessageDistributor MessageService
        {
            get
            {
                return MessageDistributor.GetMessageService(this.ServiceName);
            }
        }
        public TMyType GetFunctionService<TMyType>() where TMyType:IStandardService
        {
                return (TMyType)((IStandardService)FunctionServiceConnector.GetFunctionService<T>(this.ServiceName));
        }
        public void CloseService()
        {
            MessageDistributor.CloseMessageService(this.ServiceName);
            FunctionServiceConnector.CloseFunctionService(this.ServiceName);
        }
    }
}
